package UI;

import util.Util;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * When you click on this MenuItem, it reads a file name from <code>fileNameTextField</code> and a version from <code>versionTextField</code> and gets it from the repository.
 * @author  Anna
 */
public class GetFileMenuItem extends SpecialMenuItem {
    public GetFileMenuItem(){
        super("Get file");
        addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                String s = fileNameTextField.getText();
                try{
                  int version = ( new Integer(versionTextField.getText()) ).intValue();

                  /*
                  Added by Mihail A. Muhin to test program's functionality.
                  istead of:
                      connect.getFile(s, version);
                  */
                  String contents=connect.getFile(s, version);
                  Util.ShowDialog("File: "+s+" version: "+Integer.toString(version),contents);
                  textArea.setText(contents);

                  /*
                  Addition end
                  */

                } catch(NumberFormatException nfe){
                    //UI.Surface.errLabel.setText("incorrect version number!");
                }

            }
        });
    }
}
